package com.evil.application.pojo.dto.reporting.data;

import cn.hutool.core.bean.BeanUtil;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 报表数据 单元格
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Data
@Accessors(chain = true)
public class ReportingTableDataDTO {

    /**
     * 是否隐藏单元格
     */
    private Boolean cellHide;

    /**
     * 列宽
     */
    private Integer columnSpan;

    /**
     * 日期（暂无）
     */
    private Date dateAccuracy;

    /**
     * 行高
     */
    private Integer rowSpan;

    /**
     * 单元格值
     */
    private String value;

    /**
     * 是否小计列
     */
    private Boolean isTotalColumn;

    public ReportingTableDataDTO() {
        this.cellHide = false;
        this.columnSpan = 1;
        this.rowSpan = 1;
        this.isTotalColumn = false;
    }

    public ReportingTableDataDTO(String value) {
        this.cellHide = false;
        this.columnSpan = 1;
        this.rowSpan = 1;
        this.value = value;
        this.isTotalColumn = false;
    }

    @Override
    public boolean equals(Object o) {
        return this == o;
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    public ReportingTableDataDTO copy() {
        return BeanUtil.copyProperties(this, ReportingTableDataDTO.class);
    }

    public void copyProp(ReportingTableDataDTO data) {
        this.cellHide = data.cellHide;
        this.columnSpan = data.columnSpan;
        this.rowSpan = data.rowSpan;
        this.value = data.value;
        this.isTotalColumn = data.isTotalColumn;
    }

    public static List<ReportingTableDataDTO> copyList(List<ReportingTableDataDTO> dataHeaders) {
        return dataHeaders.stream().map(e -> BeanUtil.copyProperties(e, e.getClass())).collect(Collectors.toList());
    }

    public static List<ReportingTableDataDTO> generateEmptyCell(int num, boolean cellHide) {
        List<ReportingTableDataDTO> emptyCells = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            emptyCells.add(new ReportingTableDataDTO().setCellHide(cellHide));
        }
        return emptyCells;
    }

    public static ReportingTableDataDTO[][] generateEmptyCell(int x, int y) {
        ReportingTableDataDTO[][] collectValues = new ReportingTableDataDTO[x][y];
        for (int i = 0; i < x; i++) {
            collectValues[i] = ReportingTableDataDTO.generateEmptyCell(y);
        }
        return collectValues;
    }

    public static ReportingTableDataDTO[] generateEmptyCell(int y) {
        ReportingTableDataDTO[] collectValues = new ReportingTableDataDTO[y];
        for (int j = 0; j < y; j++) {
            collectValues[j] = new ReportingTableDataDTO();
        }
        return collectValues;
    }
}
